package com.blog.controller;

import com.alibaba.fastjson.JSON;
import com.blog.model.User;
import com.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class LoginController {
    @Autowired
    private UserService userService;

    /**
     * 登录判断
     * @param user
     * @return
     */
    @RequestMapping("/login")
    public String login (@RequestBody User user){
        String data = "error";
        User users = userService.getByUser(user.getAccount(), user.getPassword());
        System.out.println("user:"+users);
        HashMap<String,Object> res = new HashMap<>();
        if (users!=null){
            data="ok";
        }
        res.put("data",data);
        res.put("user",users);
        String res_json = JSON.toJSONString(res);
        return res_json;
    }
}
